home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / misc / update / tpasc302.cpt / TCL Update / New More Files / CCharGrid.p < prev    next >
Encoding:
Text File  |  1990-05-11  |  3.3 KB  |  126 lines

  1. {****************************************************}
  2. {         CCharGrid.p}
  3. {}
  4. {        The CharGrid Class}
  5. {}
  6. {        A grid where each item is a character from a single font. Since}
  7. {        fonts are just bitmaps, a font editor can be used to create one}
  8. {        where each "character" is really a small picture. This is how a}
  9. {        palette of tools is typically implemented.}
  10. {}
  11. {        SUPERCLASS = CGridSelector}
  12. {}
  13. {        Copyright ⌐ 1989, Symantec Corporation.  All rights reserved.            }
  14. {}
  15. {****************************************************}
  16.  
  17. unit CCharGrid;
  18.  
  19. interface
  20.  
  21.     uses
  22.         TCL, MoreTCL;
  23.  
  24.     type
  25.  
  26.         ChGdRec = record        { Resource template for a char grid }
  27.                 rows: integer;
  28.                 cols: integer;
  29.                 boxWidth: integer;
  30.                 boxHeight: integer;
  31.                 hSizing: integer;
  32.                 vSizing: integer;
  33.                 hLoc: integer;
  34.                 vLoc: integer;
  35.                 commandBase: integer;
  36.                 theSize: integer;
  37.                 extra: packed array[0..511] of char;        {"Extra" contains two            }
  38.                                                             {pascal strings:  the font name    }
  39.                                                             {followed by the characters.    }
  40.             end;
  41.  
  42.         ChGdPtr = ^ChGdRec;
  43.         ChGdHand = ^ChGdPtr;
  44.  
  45.  
  46. implementation
  47.  
  48.  
  49. {****************************************************}
  50. { ICharGrid}
  51. {}
  52. {        Initialize a CharGrid object}
  53. {}
  54. {****************************************************}
  55.  
  56.     procedure CCharGrid.ICharGrid (ChGdid: integer; anEnclosure: CView; aSupervisor: CBureaucrat);
  57.         var
  58.             r: ChGdHand;
  59.             p: ChGdPtr;
  60.             aTextInfo: TextInfoRec;
  61.             i: integer;
  62.             fontName: Str255;
  63.             theEnvironment: CEnvironment;       { Altered by TCL Weaver 1.0 (5/9/90) }
  64.  
  65.     begin
  66.         r := ChGdHand(GetResource('ChGd', ChGdid));
  67.         CheckResource(Handle(r));
  68.         HLock(Handle(r));
  69.         p := r^;
  70.  
  71.         IGridSelector(anEnclosure, aSupervisor, p^.hLoc, p^.vLoc, SizingOption(p^.hSizing), SizingOption(p^.vSizing), 1, p^.commandBase, p^.rows, p^.cols, p^.boxWidth, p^.boxHeight);
  72.  
  73.         aTextInfo.theSize := p^.theSize;
  74.         aTextInfo.theStyle := [];
  75.         aTextInfo.theMode := srcOr;
  76.  
  77.         BlockMove(@p^.extra[0], @fontName, ord(p^.extra[0]) + 1);
  78.         GetFontNumber(fontName, aTextInfo.fontNumber);
  79.  
  80.         i := ord(p^.extra[ord(p^.extra[0]) + 1]);
  81.         theCharacters := ChGdArrayH(NewHandle(i));
  82.         BlockMove(@p^.extra[ord(p^.extra[0]) + 2], @theCharacters^^, ord(p^.extra[ord(p^.extra[0]) + 1]));
  83.  
  84.         HUnlock(Handle(r));
  85.  
  86.         new(CTextEnvirons(theEnvironment)); { Altered by TCL Weaver 1.0 (5/9/90) }
  87.         itsEnvironment := theEnvironment;
  88.         CTextEnvirons(itsEnvironment).SetTextInfo(aTextInfo);
  89.     end;
  90.  
  91.  
  92. {****************************************************}
  93. { Free (OVERRIDE)}
  94. {}
  95. {        Dispose of a character grid}
  96. {}
  97. {****************************************************}
  98.  
  99.     procedure CCharGrid.Free;
  100.     begin
  101.         DisposHandle(Handle(theCharacters));         {Get rid of list of characters        }
  102.         inherited Free;                                { Pass message on to superclass    }
  103.     end;
  104.  
  105.  
  106. {****************************************************}
  107. { DrawItem (OVERRIDE)}
  108. {}
  109. {        Draw the character at the specified row and column}
  110. {}
  111. {****************************************************}
  112.  
  113.     procedure CCharGrid.DrawItem (theItem: integer; theBox: Rect);
  114.         var
  115.             fInfo: FontInfo;            { Info about the font                }
  116.             theChar: char;
  117.  
  118.     begin
  119.         GetFontInfo(fInfo);
  120.         theChar := theCharacters^^[theItem - 1];
  121.         MoveTo(theBox.left + (boxWidth - CharWidth(theChar)) div 2, theBox.bottom - (boxHeight - fInfo.ascent - fInfo.descent) div 2);
  122.         DrawChar(theChar);
  123.     end;
  124.  
  125.  
  126. end.